package com.heima.wemedia.listener;

import com.heima.common.constants.MqConstants;
import com.heima.wemedia.service.WmNewsAutoScanService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class WemediaListener {

    @Autowired
    private WmNewsAutoScanService wmNewsAutoScanService;

    /**
     * 监听定时发布时间
     * 延时审核
     * @param wmNewsId
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = MqConstants.TOTIAO_DELAY_QUEUE, durable = "true"),
            exchange = @Exchange(name = MqConstants.TOTIAO_EXCHANGE, delayed = "true"),
            key = MqConstants.TOTIAO_DELAY_KEY))
    public void listenDelayQueue(String wmNewsId){
        System.out.println((new Date()) + "文章发布啦..." + wmNewsId);
        wmNewsAutoScanService.autoScanWmNews(Integer.valueOf(wmNewsId));
    }

}